package com.lancer.cloud.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lancer.cloud.common.base.service.impl.BaseServiceImpl;
import com.lancer.cloud.user.entity.SysDict;
import com.lancer.cloud.user.mapper.SysDictMapper;
import com.lancer.cloud.user.service.SysDictService;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 数据库字典实现类
 *
 * @author caijinbang
 * @date 2019-01-23 10:57
 */
@Service
public class SysDictServiceImpl extends BaseServiceImpl<SysDictMapper, SysDict> implements SysDictService {

    private static final Integer TOP_PARENT_ID = -1;

    /**
     * 根据描述获取顶级数据字典列表
     *
     * @param desc 描述
     * @return
     */
    @Override
    public List<SysDict> getTopDictListByDesc(String desc) {
        QueryWrapper<SysDict> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
            .eq(SysDict::getParentId, TOP_PARENT_ID)
            .like(StringUtils.isNotBlank(desc), SysDict::getDesc, desc);
        return baseMapper.selectList(queryWrapper);
    }
}
